package edu.gdit.health.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.gdit.health.base.Results;
import edu.gdit.health.dao.SysDictDao;
import edu.gdit.health.dao.SysReportCountDao;
import edu.gdit.health.dao.SysReportDao;
import edu.gdit.health.model.SysDict;
import edu.gdit.health.model.SysReport;
import edu.gdit.health.model.SysReportCount;
import edu.gdit.health.service.SysReportService;

@Service
public class SysReportServiceImpl implements SysReportService
{
    @Autowired
    private SysReportDao sysReportDao;
    @Autowired
    private SysReportCountDao sysReportCountDao;
    @Autowired
    private SysDictDao sysDictDao;
	@Override
	public int add(SysReport sysReport) {
		// TODO Auto-generated method stub
		return sysReportDao.save(sysReport);
	}
	@Override
	public Map<String, List<SysDict>> getTypes() {
		Map<String,List<SysDict>> dict=new HashMap<>();
        //放置三对（key,value）
        dict.put("temperature",new ArrayList<SysDict>());
        dict.put("travel",new ArrayList<SysDict>());
        dict.put("physical_condition",new ArrayList<SysDict>());
        //为每对（key,value）的value赋值,第一个temperature
        dict.get("temperature").add(new SysDict("NORMAL","正常 37.3℃ 以下"));
        dict.get("temperature").add(new SysDict("LOW" , "低热 37.3-37.9℃"));
        dict.get("temperature").add(new SysDict("MIDDLE" , "中热 38-39℃"));
        dict.get("temperature").add(new SysDict("HIGH" , "高热 39℃以上"));
        //为每对（key,value）的value赋值,第二个travel
        dict.get("travel").add(new SysDict("1","有旅游"));
        dict.get("travel").add(new SysDict("0","没有旅游"));

        //为每对（key,value）的value赋值,physical_condition
        dict.get("physical_condition").add(new SysDict("travel" , "14天内曾居住或前往疫情高发地"));
        dict.get("physical_condition").add(new SysDict("contact" , "两周内有与确诊患者接触"));
        dict.get("physical_condition").add(new SysDict("normal" , "没有出现症状"));
        dict.get("physical_condition").add(new SysDict("rheum" , "感冒样症状：乏力、精神差、咳嗽、发烧、肌肉痛、头痛"));
        dict.get("physical_condition").add(new SysDict("polypnea" , "喘憋、呼吸急促"));
        dict.get("physical_condition").add(new SysDict("vomiting" , "恶心呕吐、腹泻"));
        dict.get("physical_condition").add(new SysDict("flustered" , "心慌、胸闷"));
        dict.get("physical_condition").add(new SysDict("conjunctivitis" , "结膜炎（红眼病样表现：眼睛涩、红、分泌物）"));
        return dict;
	}
	/*
	 * @Override public Results refresh() { this.countReportData(new Date()); return
	 * Results.success(); }
	 */

	@Override
	public void countReportData(Date now) {
	    String startDate, endDate;
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	    startDate = endDate = sdf.format(now);
	    List<SysReportCount> temperatureData = sysReportDao.getChartTemperatureData(startDate, endDate);

	  for (SysReportCount item : temperatureData) {
	    item.setType("temperature");
	    item.setReportDate(endDate);
	    item.setCreateTime(now);
	    sysReportCountDao.delete(item);
	    sysReportCountDao.save(item);
	}
	}
	@Override
	public Results getChartTemperatureData() {
		// TODO Auto-generated method stub
		 List<SysReportCount> data = sysReportCountDao.query("temperature");
	        return Results.success(data);
	}

	
	
	
}
